package cn.ihww.mybatis.service.impl;

import cn.ihww.mybatis.dao.UserMapper;
import cn.ihww.mybatis.model.User;
import cn.ihww.mybatis.service.IUserService;
import com.iwjw.ibatis.annotations.MasterMark;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: huangweiwei
 * @email: ihuangweiwei@163.com
 * @created:2016/10/28
 */
@Service
public class UserService implements IUserService {

    @Resource
    UserMapper userMapper;

    public boolean save(User user) {
        return this.userMapper.insertSelective(user) > 0;
    }

    public User get(Long id) {
        return this.userMapper.selectByPrimaryKey(id);
    }

    public User getByMaster(Long id) {

        return this.userMapper.selectByPrimaryKey(id, MasterMark.MASTER);
    }

    public boolean delete(Long id) {
        return this.userMapper.deleteByPrimaryKey(id) == 1;
    }

    public boolean update(User user) {
        return this.userMapper.updateByPrimaryKeyNoOptimistic(user) == 1;
    }


}
